<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Livekit test app</title>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
      integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
      crossorigin="anonymous"
    />

    <style>
      .video-container {
        display: inline-block;
        border-radius: 5px;
      }

      .video-container video.speaking {
        border: 4px solid rgba(94, 166, 190, 0.7);
      }
    </style>
  </head>

  <body>
    <div class="container">
      <div class="row">
        <div class="col-md-8">
          <h2>Livekit Sample App</h2>
          <br/>
          <form>
            <div class="form-group row">
              <label for="url" class="col-md-3 col-form-label"
                >LiveKit URL</label
              >
              <input
                type="text"
                class="form-control col-md-5"
                id="url"
                value="ws://localhost:7880"
              />
            </div>

            <div class="form-group row">
              <label for="token" class="col-md-3 col-form-label">Token</label>
              <input type="text" class="form-control col-md-5" id="token" />
            </div>

            <div class="form-group row">
              <div class="col-md-2 offset-md-1">
                <div class="form-check">
                  <input
                    type="checkbox"
                    class="form-check-input"
                    id="publish-option"
                    checked
                  />
                  <label for="checkbox" class="form-check-label">
                    Publish
                  </label>
                </div>
              </div>
              <div class="col-md-2">
                <div class="form-check">
                  <input
                    type="checkbox"
                    class="form-check-input"
                    id="simulcast"
                    checked
                  />
                  <label for="checkbox" class="form-check-label">
                    Simulcast
                  </label>
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-check">
                  <input
                    type="checkbox"
                    class="form-check-input"
                    id="force-turn"
                  />
                  <label for="checkbox" class="form-check-label">
                    Force TURN
                  </label>
                </div>
              </div>
            </div>

            <div class="form-group row">
              <div class="col-md-2">
                <button
                  id="connect-button"
                  class="btn btn-primary mt-1"
                  type="button"
                  onclick="connectWithFormInput()"
                >
                  Connect
                </button>
              </div>
              <div class="col-md-10">
                <button
                  id="toggle-audio-button"
                  class="btn btn-secondary mt-1"
                  disabled
                  type="button"
                  onclick="toggleAudio()"
                >
                  Enable Audio
                </button>
                <button
                  id="toggle-video-button"
                  class="btn btn-secondary mt-1"
                  disabled
                  type="button"
                  onclick="toggleVideo()"
                >
                  Enable Video
                </button>
                <button
                  id="flip-video-button"
                  class="btn btn-secondary mt-1"
                  disabled
                  type="button"
                  onclick="flipVideo()"
                >
                  Back Camera
                </button>
                <button
                  id="share-screen-button"
                  class="btn btn-secondary mt-1"
                  disabled
                  type="button"
                  onclick="shareScreen()"
                >
                  Share Screen
                </button>
                <button
                  id="disconnect-ws-button"
                  class="btn btn-warning mt-1"
                  disabled
                  type="button"
                  onclick="disconnectSignal()"
                >
                  WS Reconnect
                </button>
                <button
                  id="disconnect-room-button"
                  class="btn btn-danger mt-1"
                  disabled
                  type="button"
                  onclick="disconnectRoom()"
                >
                  Disconnect
                </button>
                <button
                  id="start-audio-button"
                  class="btn btn-secondary mt-1"
                  disabled
                  type="button"
                  onclick="startAudio()"
                >
                  Enable Audio
                </button>
              </div>
            </div>

            <!-- video devices -->
            <div class="form-group row">
              <div class="col-md-4">
                <select id="video-input" class="custom-select" onchange="handleDeviceSelected(event)">
                  <option selected>Video Input (default)</option>
                </select>
              </div>
              <div class="col-md-4">
                <select id="audio-input" class="custom-select" onchange="handleDeviceSelected(event)">
                  <option selected>Audio Input (default)</option>
                </select>
              </div>
              <div class="col-md-4">
                <select id="audio-output" class="custom-select" onchange="handleDeviceSelected(event)">
                  <option selected>Audio Output (default)</option>
                </select>
              </div>
            </div>

            <div class="form-group row">
              <textarea
                class="form-control col-md-12"
                id="log"
                rows="5"
              ></textarea>
            </div>
          </form>
        </div>
        <div class="col-md-4">
          <h3>Chat</h3>
          <div class="row">
            <div class="col-md-12">
              <textarea class="form-control" id="chat" rows="15"></textarea>
            </div>
          </div>
          <div class="row mt-1">
            <div class="col-md-10">
              <input type="text" class="form-control" id="entry" />
            </div>
            <div class="col-md-1">
              <button
                class="btn btn-primary"
                type="button"
                onclick="enterText()"
              >
                Enter
              </button>
            </div>
          </div>
        </div>
      </div>

      <div class="row" id="remote-area"></div>
      <div class="row" id="local-area">
        <div class="col-md-6 video-container" id="local-video"></div>
      </div>
    </div>
    <script src="bundle.js"></script>
  </body>
</html>
